package concurrency;

public class JoinThread {

	public static void main(String[] args) {
		Thread t = new MyThread(1000);
		Thread t2 = new MyThread(3000);
		
		try {
			t.start();
			t2.start();
			t.join();
		} catch (InterruptedException e) { }
		
		System.out.println("End of main!");
	}
	
	static class MyThread extends Thread {
		
		private int sleepTime;
		
		public MyThread(int sleepTime) {
			super("MyThread:"+sleepTime);
			this.sleepTime = sleepTime;
		}

		@Override
		public void run() {
			try {
				System.out.println("MyThread will sleep for "+this.sleepTime+ " ms");
				Thread.sleep(this.sleepTime);
			} catch (InterruptedException e) { }
			
			System.out.println("MyThread wake up after "+this.sleepTime+" ms");
		}
	}
}

